home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / util / libs / ttrender.lha / ttrender-3.1 / Examples / test.c < prev   
C/C++ Source or Header  |  2002-05-28  |  6KB  |  148 lines

  1. /* test ttrender */
  2.  
  3. #define __NOLIBBASE__
  4.  
  5. #include <proto/dos.h>
  6. #include <proto/exec.h>
  7. #include <proto/intuition.h>
  8. #include <proto/graphics.h>
  9. #include <proto/ttrender.h>
  10. #include <proto/asl.h>
  11.  
  12. #include <libraries/ttrender.h>
  13.  
  14. extern struct Library *SysBase, *DOSBase;
  15.  
  16. /*----------------------------------------------------------------------------------------------------*/
  17.  
  18. static STRPTR get_font_name(struct Library *AslBase)
  19.   {
  20.     struct FileRequester *freq;
  21.     STRPTR name = NULL;
  22.  
  23.     if (freq = AllocAslRequestTags(ASL_FileRequest, TAG_END))
  24.       {
  25.         if (AslRequestTags(freq,
  26.           ASLFR_TitleText, (ULONG)"Select TrueType font",
  27.           ASLFR_InitialDrawer, (ULONG)"FONTS:_TrueType_Outlines/",
  28.           ASLFR_DoPatterns, TRUE,
  29.           ASLFR_InitialPattern, (ULONG)"#?.ttf",
  30.           ASLFR_RejectIcons, TRUE,
  31.           TAG_END))
  32.           {
  33.             ULONG namelen = strlen(freq->fr_File) - 4;
  34.  
  35.             if (name = AllocVec(namelen + 1, MEMF_ANY | MEMF_CLEAR))
  36.               {
  37.                 strncpy(name, freq->fr_File, namelen);
  38.               }
  39.           }
  40.         FreeAslRequest(freq);
  41.       }
  42.     return name;
  43.   }
  44.  
  45. /*----------------------------------------------------------------------------------------------------*/
  46.  
  47. static VOID free_font_name(STRPTR name)
  48.   {
  49.     if (name) FreeVec(name);
  50.   }
  51.  
  52. /*----------------------------------------------------------------------------------------------------*/
  53.  
  54. UWORD tx[] = {'T', 'e', 's', 't', ' ', '1', '6', '-', 'b', 'i', 't', ' ', 'U', 'n', 'i',
  55.  'c', 'o', 'd', 'e', ' ', 's', 't', 'r', 'i', 'n', 'g', '.', 0x0000};
  56.  
  57. int Main (void)
  58.   {
  59.     struct Library *TTRenderBase, *IntuitionBase, *GfxBase, *AslBase;
  60.     struct Window *win;
  61.     STRPTR fontname;
  62.  
  63.     if (GfxBase = OpenLibrary("graphics.library", 39))
  64.       {
  65.         if (IntuitionBase = OpenLibrary("intuition.library", 39))
  66.           {
  67.             if (AslBase = OpenLibrary("asl.library", 38))
  68.               {
  69.                 if (fontname = get_font_name(AslBase))
  70.                   {
  71.                     if (TTRenderBase = OpenLibrary("ttrender.library", 0))
  72.                       {
  73.                         if (win = OpenWindowTags(NULL,
  74.                           WA_Top, 25,
  75.                           WA_Left, 0,
  76.                           WA_Width, 640,
  77.                           WA_Height, 250,
  78.                           WA_CloseGadget, TRUE,
  79.                           WA_DragBar, TRUE,
  80.                           WA_DepthGadget, TRUE,
  81.                           WA_IDCMP, IDCMP_CLOSEWINDOW,
  82.                           WA_Title, (ULONG)"ttrender.library test",
  83.                           TAG_END))
  84.                           {
  85.                             ULONG sigmask, signals;
  86.                             BOOL running = TRUE;
  87.                             struct RastPort *rp = win->RPort;
  88.  
  89.                             TT_SetModesTags(TTA_Window, (ULONG)win, TAG_END);
  90.                             TT_SetFont(fontname, 36);
  91.                             SetAPen(rp, 1);
  92.                             SetDrMd(rp, JAM1);
  93.                             Move(rp, 10, 50);
  94.                             TT_PutStr("This is a text printed with TT_PutStr().");
  95.                             SetAPen(rp, 2);
  96.                             Move(rp, 10, 86);
  97.                             TT_PutUStr(tx);
  98.                             Move(rp, 10, 122);
  99.                             SetAPen(rp, 3);
  100.                             TT_PutStrTags("Local antialias on.", TTA_Antialias, TRUE, TAG_END);
  101.                             Move(rp, 10, 134);
  102.                             TT_SetFont(fontname, 14);
  103.                             Move(rp, 10, 154);
  104.                             SetAPen(rp, 1);
  105.                             TT_PutStr("Font size change. 14 points for now. This text can be a bit longer. Kerning sample: AVAVAVATA.");
  106.                             SetAPen(rp, 2);
  107.                             SetBPen(rp, 1);
  108.                             SetDrMd(rp, JAM2);
  109.                             Move(rp, 10, 180);
  110.                             TT_SetFont(fontname, 21);
  111.                             TT_PutStrTags("Test of JAM2 RastPort mode, 21 pixels size, antialias on.",
  112.                               TTA_Antialias, TRUE,
  113.                               TAG_END);
  114.                             Move(rp, 10, 201);
  115.                             TT_PutStrTags("JAM2 background filling - there should be no background between the lines.",
  116.                               TTA_Antialias, TRUE,
  117.                               TAG_END);
  118.                             sigmask = SIGBREAKF_CTRL_C | (1 << win->UserPort->mp_SigBit);
  119.                             while (running)
  120.                               {
  121.                                 signals = Wait(sigmask);
  122.                                 if (signals & SIGBREAKF_CTRL_C) running = FALSE;
  123.                                 if (signals & (1 << win->UserPort->mp_SigBit))
  124.                                   {
  125.                                     struct IntuiMessage *imsg;
  126.  
  127.                                     while (imsg = (struct IntuiMessage*)GetMsg(win->UserPort))
  128.                                       {
  129.                                         if (imsg->Class == IDCMP_CLOSEWINDOW) running = FALSE;
  130.                                         ReplyMsg((struct Message*)imsg);
  131.                                       }
  132.                                   }
  133.                               }
  134.                             CloseWindow(win);
  135.                           }
  136.                         CloseLibrary(TTRenderBase);
  137.                       }
  138.                     free_font_name(fontname);
  139.                   }
  140.                 CloseLibrary(AslBase);
  141.               }
  142.             CloseLibrary(IntuitionBase);
  143.           }
  144.         CloseLibrary(GfxBase);
  145.       }
  146.     return 0;
  147.   }
  148.